﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using SampleV1;

namespace FarseerPhysics.SamplesFramework
{
    /// <summary>
    /// The background screen sits behind all the other menu screens.
    /// It draws a background image that remains fixed in place regardless
    /// of whatever transitions the screens on top of it may be doing.
    /// </summary>
    public class BackgroundScreen : GameScreen
    {
        //private const float LogoScreenHeightRatio = 0.25f;
        //private const float LogoScreenBorderRatio = 0.0375f;
        //private const float LogoWidthHeightRatio = 1.4f;

        private Texture2D _backgroundTexture;
        private Rectangle play01;
        private MenuButton playButton;
        private Rectangle _viewport;

        /// <summary>
        /// Constructor.
        /// </summary>
        public BackgroundScreen()
        {
            HasCursor = true;
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }

        public override void LoadContent()
        {
            Texture2D playTexture = ScreenManager.Content.Load<Texture2D>("Man2/Play");
             Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            playButton = new MenuButton(playTexture, false, new Vector2(viewport.Width/2, viewport.Height/2 - playTexture.Height / 4), this);
            _backgroundTexture = ScreenManager.Content.Load<Texture2D>("Man3/angry_bird");
           
            play01 = new Rectangle(viewport.Width / 3, viewport.Height / 4, 300, 300);
            //Vector2 logoSize = new Vector2();
            //logoSize.Y = viewport.Height * LogoScreenHeightRatio;
            //logoSize.X = logoSize.Y * LogoWidthHeightRatio;

            //float border = viewport.Height * LogoScreenBorderRatio;
            //Vector2 logoPosition = new Vector2(viewport.Width - border - logoSize.X,
            //                                   viewport.Height - border - logoSize.Y);
            //_logoDestination = new Rectangle((int)logoPosition.X, (int)logoPosition.Y, (int)logoSize.X,
            //                                 (int)logoSize.Y);
            _viewport = viewport.Bounds;
            base.LoadContent();
        }

        /// <summary>
        /// Updates the background screen. Unlike most screens, this should not
        /// transition off even if it has been covered by another screen: it is
        /// supposed to be covered, after all! This overload forces the
        /// coveredByOtherScreen parameter to false in order to stop the base
        /// Update method wanting to transition off.
        /// </summary>
        /// 

        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.IsCursorValid)
            {
                playButton.Collide(input.Cursor);
            }
            else
            {
                playButton.Hover = false;
            }
            if (input.IsNewKeyPress(Keys.Escape)){
                ExitScreen();
            }//end if
            else 
            if (playButton.Hover&&input.IsNewMouseButtonPress(MouseButtons.LeftButton)){
                //ExitScreen();
                ScreenManager.AddScreen(((Game1)ScreenManager.Game).screen1);
            }//end if
        }//end method

        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            
            base.Update(gameTime, otherScreenHasFocus, false);
            playButton.Update(gameTime);
        }

        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(_backgroundTexture, _viewport, Color.White);
            playButton.Draw();
            ScreenManager.SpriteBatch.End();
        }

    }
}